package com.example.system.controller.contest;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.TableDataInfo;
import com.example.system.domain.contest.DTO.ContestAddDTO;
import com.example.system.domain.contest.DTO.ContestEditDTO;
import com.example.system.domain.contest.DTO.ContestQueryDTO;
import com.example.system.domain.contest.DTO.ContestQuestionADDDTO;
import com.example.system.domain.contest.vo.ContestDetailVO;
import com.example.system.service.contest.ContestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/contest")
public class ContestController extends BaseController {
    @Autowired
    private ContestService contestService;

    @GetMapping("/list")
    public TableDataInfo list(ContestQueryDTO contestQueryDTO) {
        return getDataTable(contestService.list(contestQueryDTO));
    }

    @PostMapping("/add")
    public R<String> add(@RequestBody ContestAddDTO contestAddDTO) {
        return contestService.add(contestAddDTO);
    }

    @PostMapping("/question/add")
    public R<Void> addQuestion(@RequestBody ContestQuestionADDDTO contestQuestionADDDTO) {
        return toR(contestService.addQuestion(contestQuestionADDDTO));
    }

    @DeleteMapping("/question/delete")
    public R<Void> deleteQuestion(Long contestId, Long questionId) {
        return toR(contestService.deleteQuestion(contestId, questionId));
    }
    @GetMapping("/detail")
    public R<ContestDetailVO> detail(Long id) {
        return contestService.detail(id);
    }

    @PutMapping("/edit")
    public R<Void> update(@RequestBody ContestEditDTO contestEditDTO) {
        return toR(contestService.edit(contestEditDTO));
    }

    @DeleteMapping("/delete")
    public R<Void> delete(Long id) {
        return toR(contestService.delete(id));
    }

    @PutMapping("/publish")
    public R<Void> publish(Long id) {
        return toR(contestService.publish(id));
    }

    @PutMapping("/cancelPublish")
    public R<Void> cancelPublish(Long id) {
        return toR(contestService.cancelPublish(id));
    }
}
